package com.ktwlsoft.archivemanage.domain.business.repositoryService;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ktwlsoft.archivemanage.domain.dao.entity.InstructionDic;
import com.ktwlsoft.archivemanage.domain.dao.repository.InstructionDicMapper;
import lombok.Getter;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Joker
 * @version 1.0
 */
@Service
public class InstructionDicRepositoryService {
    @Getter
    private final InstructionDicMapper instructionDicMapper;

    public InstructionDicRepositoryService(InstructionDicMapper instructionDicMapper) {
        this.instructionDicMapper = instructionDicMapper;
    }

    /**
     * 指南字典查询分页
     *
     * @param pn       第几页
     * @param pageSize 每页多少条
     * @return PageInfo<InstructionDic>
     */
    public PageInfo<InstructionDic> findPage(int pn, int pageSize, String businessFrom) {
        PageHelper.startPage(pn, pageSize);
        PageInfo<InstructionDic> pageInfo = new PageInfo<InstructionDic>(instructionDicMapper.selectByBusinessFrom(businessFrom));
        return pageInfo;
    }

    /**
     * 根据I指南字典D查询信息
     *
     * @param id 主键
     * @return MessageManage
     */
    public InstructionDic getById(Long id) {
        return instructionDicMapper.selectByPrimaryKey(id);
    }

    /**
     * 指南字典新增
     *
     * @param instructionDic instructionDic
     * @return int
     */
    public int insert(InstructionDic instructionDic) {
        return instructionDicMapper.insert(instructionDic);
    }

    /**
     * 指南字典修改
     *
     * @param instructionDic instructionDic
     * @return int
     */
    public int update(InstructionDic instructionDic) {
        return instructionDicMapper.updateByPrimaryKey(instructionDic);
    }

    /**
     * 根据指南字典id删除信息
     *
     * @param id id
     * @return int
     */
    public int deleteById(Long id) {
        return instructionDicMapper.deleteByPrimaryKey(id);
    }

    /**
     * 根据指南字典名称查询信息
     *
     * @param instructionDic instructionDic
     * @return instructionDic
     */
    public List<InstructionDic> getByName(InstructionDic instructionDic) {
        return instructionDicMapper.getByName(instructionDic);
    }

    public PageInfo<InstructionDic> getFirstPageList(Integer pn, Integer pageSize, InstructionDic.BusinessFrom businessFrom) {
        PageHelper.startPage(pn, pageSize);
        PageInfo<InstructionDic> pageInfo = new PageInfo<>(instructionDicMapper.selectFirstInstrction(businessFrom));
        return pageInfo;
    }

    /**
     * @Description 根据上级id获取下级列表
     * @dateTime 2019-12-18 11:26
     * @author wangchong
     */
    public List<InstructionDic> getChildrenById(Long id) {
        return instructionDicMapper.selectChildrenById(id);
    }
}
